﻿//--------------------------------------------------------------------
// All Rights Reserved , Copyright (C) 2011 , DotNet, Ltd.
//--------------------------------------------------------------------

using System;
using System.Data;
using System.Drawing;
using System.Windows.Forms;

namespace DotNet.WinForm.Organize
{
    using DotNet.Model;
    using DotNet.Service;
    using DotNet.Utilities;
    using DotNet.WinForm.Utilities;

    /// <summary>
    /// FrmOrganizeAdmin
    /// 组织机构管理-管理组织机构窗体
    ///
    /// 修改记录
    ///
    ///     2008.10.27 版本：2.1 DotNet 整理权限主键。
    ///     2008.09.25 版本：2.0 DotNet 树型架构的节点加载顺序问题。
    ///     2008.02.05 版本：1.9 DotNet 速度性能进行优化。
    ///     2007.06.14 版本：1.8 DotNet 增加权限判断主键。
    ///     2007.06.05 版本：1.7 DotNet 整理主键。
    ///     2007.06.01 版本：1.6 DotNet 进行优化。
    ///     2007.05.30 版本：1.5 DotNet SingleDelete() 进行优化。
    ///     2007.05.29 版本：1.4 DotNet 删除移动的主键优化，提示信息优化，标准工程完成。
    ///     2007.05.28 版本：1.3 DotNet 整体整理主键。
    ///     2007.05.17 版本：1.2 DotNet 增加了多国语言功能，调整了细节部分。
    ///     2007.05.15 版本：1.1 DotNet 整体进行调试改进。
    ///     2007.05.12 版本：1.0 DotNet 组织机构管理功能页面编写。
    ///
    /// 版本：2.0
    ///
    /// <author>
    ///		<name>DotNet</name>
    ///		<date>2008.09.25</date>
    /// </author>
    /// </summary>
    public partial class FrmOrganizeAdmin : BaseForm, IBaseForm
    {
        private bool permissionAccess = false;    // 访问权限
        private bool permissionAddRoot = false;    // 新增组织机构权限
        private bool permissionAdd = false;    // 新增组织机构权限
        private bool permissionEdit = false;    // 编辑组织机构权限
        private bool permissionDelete = false;    // 删除组织机构权限
        private bool permissionMove = false;    // 移动组织机构
        private bool permissionExport = false;    // 导出
        private bool permissionAccredit = false; // 用户授权

        /// <summary>
        /// 权限域编号
        /// </summary>
        public string ByPermission = "SystemAdmin";

        private DataTable DTOrganize = new DataTable(BaseOrganizeTable.TableName);      // 组织机构列表 DataTable
        private DataTable DTOrganizeList = new DataTable(BaseOrganizeTable.TableName);  // 组织机构列表 DataTable

        private System.Windows.Forms.Control LastControl = null;  // 记录最后点击的控件

        public event SetControlStateEventHandler OnButtonStateChange;

        /// <summary>
        /// 设置是否为及时刷新的属性
        /// </summary>
        public bool RefreshData
        {
            set
            {
                this.chkRefresh.Checked = value;
            }
            get
            {
                return this.chkRefresh.Checked;
            }
        }

        /// <summary>
        /// 是否采用角色数据
        /// </summary>
        public bool UseRole = true;

        private string parentEntityId = string.Empty;

        /// <summary>
        /// 导航栏机构主键
        /// </summary>
        public string ParentEntityId
        {
            get
            {
                if ((this.tvOrganize.SelectedNode != null) && (this.tvOrganize.SelectedNode.Tag != null))
                {
                    this.parentEntityId = this.tvOrganize.SelectedNode.Tag.ToString();
                }
                else
                {
                    this.parentEntityId = string.Empty;
                }
                return this.parentEntityId;
            }
            set
            {
                this.parentEntityId = value;
            }
        }

        /// <summary>
        /// 表格中的组织机构主键
        /// </summary>
        public override string EntityId
        {
            get
            {
                return BaseInterfaceLogic.GetDataGridViewEntityID(this.grdOrganize, BaseOrganizeTable.FieldId);
            }
        }

        /// <summary>
        /// 当前选中的节点，树或者表格上
        /// </summary>
        public string CurrentEntityId
        {
            get
            {
                string entityId = string.Empty;
                if (this.LastControl == this.tvOrganize)
                {
                    entityId = this.ParentEntityId;
                }
                else
                {
                    entityId = this.EntityId;
                }
                return entityId;
            }
        }

        public FrmOrganizeAdmin()
        {
            InitializeComponent();
        }

        #region public override void SetControlState() 设置按钮状态

        /// <summary>
        /// 设置按钮状态
        /// </summary>
        public override void SetControlState()
        {
            this.SetSortButton(false);

            this.btnAdd.Enabled = false;
            this.btnEdit.Enabled = false;
            this.btnMove.Enabled = false;
            this.btnBatchDelete.Enabled = false;
            this.btnExport.Enabled = false;
            this.btnBatchSave.Enabled = false;

            this.mItmAdd.Enabled = false;
            this.mItmEdit.Enabled = false;
            this.mItmMove.Enabled = false;
            this.mItmDelete.Enabled = false;

            this.mItemRoleAdd.Enabled = false;
            this.mItmStaffAdd.Enabled = false;
            this.mItmOrganizeCategory.Enabled = false;
            this.mItmFrmUserPermissionReport.Enabled = false;
            this.mItmFrmCodeBuilder.Enabled = false;
            this.mItmSetSortCode.Enabled = false;

            // 检查添加权限
            this.btnAdd.Enabled = this.permissionAdd;

            if ((this.DTOrganizeList.DefaultView.Count >= 1) || (this.tvOrganize.Nodes.Count > 0))
            {
                this.btnEdit.Enabled = this.permissionEdit;
                this.btnMove.Enabled = this.permissionEdit;
                this.btnBatchDelete.Enabled = this.permissionDelete;
                if (this.DTOrganizeList.DefaultView.Count >= 1)
                {
                    this.btnExport.Enabled = this.permissionExport;
                }
            }
            if (this.DTOrganizeList.DefaultView.Count >= 1)
            {
                this.btnBatchSave.Enabled = this.permissionEdit;
            }

            // 位置顺序改变按钮部分
            if (this.DTOrganizeList.DefaultView.Count > 1)
            {
                this.SetSortButton(this.permissionEdit);
            }

            if ((this.DTOrganize.DefaultView.Count > 0) && (this.tvOrganize.Nodes.Count > 0))
            {
                this.mItmAdd.Enabled = this.permissionAdd;
                this.mItmEdit.Enabled = this.permissionEdit;
                this.mItmMove.Enabled = this.permissionEdit;
                this.mItmDelete.Enabled = this.permissionDelete;

                // 这些都是属于管理权限的杂项，Admin 权限不能轻易给别人
                this.mItmStaffAdd.Enabled = this.ModuleIsVisible("FrmRoleAdmin");
                if (this.mItmStaffAdd.Visible)
                {
                    this.mItmStaffAdd.Enabled = this.ModuleIsAuthorized("FrmStaffAdmin");
                }
                this.mItemRoleAdd.Enabled = this.ModuleIsVisible("FrmRoleAdmin");
                if (this.mItemRoleAdd.Visible)
                {
                    this.mItemRoleAdd.Enabled = this.ModuleIsAuthorized("FrmRoleAdmin");
                }
                this.mItmOrganizeCategory.Enabled = this.ModuleIsVisible("FrmItemsAdmin");
                if (this.mItmOrganizeCategory.Visible)
                {
                    this.mItmOrganizeCategory.Enabled = this.ModuleIsAuthorized("FrmItemsAdmin");
                }
                this.mItmFrmUserPermissionReport.Enabled = this.permissionAccredit;
                this.mItmFrmCodeBuilder.Enabled = this.permissionEdit;
                this.mItmSetSortCode.Enabled = this.permissionEdit;
            }

            // 添加根组织机构，什么时候都可以用才对。
            this.mItmAddRoot.Enabled = this.permissionAddRoot;

            // 检查委托是否为空
            if (OnButtonStateChange != null)
            {
                bool setTop = this.ucTableSort.SetTopEnabled;
                bool setUp = this.ucTableSort.SetUpEnabled;
                bool setDown = this.ucTableSort.SetDownEnabled;
                bool setBottom = this.ucTableSort.SetBottomEnabled;
                bool add = this.btnAdd.Enabled;
                bool edit = this.btnEdit.Enabled;
                bool batchDelete = this.btnBatchDelete.Enabled;
                bool batchSave = this.btnBatchSave.Enabled;
                OnButtonStateChange(setTop, setUp, setDown, setBottom, add, edit, batchDelete, batchSave);
            }
        }

        #endregion public override void SetControlState() 设置按钮状态

        #region public override void GetPermission() 获得页面的权限

        /// <summary>
        /// 获得页面的权限
        /// </summary>
        public override void GetPermission()
        {
            this.permissionAccess = this.IsAuthorized("OrganizeAdmin.Access");
            this.permissionAdd = this.IsAuthorized("OrganizeAdmin.Add");
            this.permissionAddRoot = this.IsAuthorized("OrganizeAdmin.AddRoot");
            this.permissionEdit = this.IsAuthorized("OrganizeAdmin.Edit");
            this.permissionMove = this.IsAuthorized("OrganizeAdmin.Move");
            this.permissionDelete = this.IsAuthorized("OrganizeAdmin.Delete");
            this.permissionExport = this.IsAuthorized("OrganizeAdmin.Export");
            this.permissionAccredit = this.IsAuthorized("Accredit");
        }

        #endregion public override void GetPermission() 获得页面的权限

        #region private void BindData(bool reloadTree) 绑定屏幕数据

        /// <summary>
        /// 绑定屏幕数据
        /// </summary>
        /// <param name="reloadTree">重新加部门载树</param>
        private void BindData(bool reloadTree)
        {
            // 加载部门树的主键
            if (reloadTree)
            {
                // 获取部门数据
                // 获取部门数据
                if (this.chkInnerOrganize.Checked)
                {
                    this.DTOrganize = ServiceManager.Instance.MessageService.GetInnerOrganize(UserInfo);
                    BaseInterfaceLogic.CheckTreeParentId(this.DTOrganize, BaseOrganizeTable.FieldId, BaseOrganizeTable.FieldParentId);
                }
                else
                {
                    this.DTOrganize = this.GetOrganizeScope(this.ByPermission);
                }
                this.LoadTree();

                if (this.tvOrganize.SelectedNode == null)
                {
                    if (this.tvOrganize.Nodes.Count > 0)
                    {
                        if (this.parentEntityId.Length == 0)
                        {
                            this.tvOrganize.SelectedNode = this.tvOrganize.Nodes[0];
                        }
                        else
                        {
                            BaseInterfaceLogic.FindTreeNode(this.tvOrganize, this.parentEntityId);
                            if (BaseInterfaceLogic.TargetNode != null)
                            {
                                this.tvOrganize.SelectedNode = BaseInterfaceLogic.TargetNode;

                                // 展开当前选中节点的所有父节点
                                BaseInterfaceLogic.ExpandTreeNode(this.tvOrganize);
                            }
                        }
                        if (this.tvOrganize.SelectedNode != null)
                        {
                            // 让选中的节点可视，并用展开方式
                            this.tvOrganize.SelectedNode.Expand();
                            this.tvOrganize.SelectedNode.EnsureVisible();
                        }
                    }
                }
            }

            // 添加选择列
            if (this.ParentEntityId.Length > 0)
            {
                if (reloadTree)
                {
                    // 获得子部门列表
                    this.GetOrganizeList();
                }
            }
            if (!this.permissionEdit)
            {
                // 只读属性设置
                this.colSelected.OptionsColumn.AllowEdit = !this.permissionEdit;
                this.colFullName.OptionsColumn.AllowEdit = !this.permissionEdit;
                this.colIsInnerOrganize.OptionsColumn.AllowEdit = !this.permissionEdit;
                this.colDescription.OptionsColumn.AllowEdit = !this.permissionEdit;

                // 修改背景颜色
                this.colFullName.AppearanceCell.BackColor = Color.White;
                this.colIsInnerOrganize.AppearanceCell.BackColor = Color.White;
                this.colDescription.AppearanceCell.BackColor = Color.White;
            }

            // 设置按钮状态
            this.SetControlState();
        }

        #endregion private void BindData(bool reloadTree) 绑定屏幕数据

        #region public override void FormOnLoad() 加载窗体

        /// <summary>
        /// 加载窗体
        /// </summary>
        public override void FormOnLoad()
        {
            // 绑定屏幕数据
            this.BindData(true);
        }

        #endregion public override void FormOnLoad() 加载窗体

        #region private void GetOrganizeList() 获得子部门列表

        /// <summary>
        /// 获得子部门列表
        /// </summary>
        private void GetOrganizeList()
        {
            // 设置鼠标繁忙状态
            this.Cursor = Cursors.WaitCursor;
            this.DTOrganizeList = ServiceManager.Instance.OrganizeService.GetDTByParent(UserInfo, this.ParentEntityId);
            this.DTOrganizeList.DefaultView.Sort = BaseOrganizeTable.FieldSortCode;
            this.DataTableAddColumn();
            this.DTOrganizeList.DefaultView.Sort = BaseOrganizeTable.FieldSortCode;
            this.grdOrganize.DataSource = this.DTOrganizeList.DefaultView;

            // 动态加载树形结构
            if (this.tvOrganize.SelectedNode.Nodes.Count == 0)
            {
                foreach (DataRow dataRow in this.DTOrganizeList.Rows)
                {
                    TreeNode treeNode = new TreeNode();
                    treeNode.Text = dataRow[BaseOrganizeTable.FieldFullName].ToString();
                    treeNode.Tag = dataRow[BaseOrganizeTable.FieldId].ToString();
                    this.tvOrganize.SelectedNode.Nodes.Add(treeNode);
                }
                this.tvOrganize.SelectedNode.Expand();
            }

            // 设置按钮状态
            this.SetControlState();

            // 设置排序按钮
            this.ucTableSort.DataBind(this.grdOrganize, this.permissionEdit);

            // 设置鼠标默认状态
            this.Cursor = Cursors.Default;
        }

        #endregion private void GetOrganizeList() 获得子部门列表

        #region private void LoadTree() 加载部门树的主键

        /// <summary>
        /// 加载部门树的主键
        /// </summary>
        private void LoadTree()
        {
            // 开始更新控件，屏幕不刷新，提高效率。
            this.tvOrganize.BeginUpdate();
            this.tvOrganize.Nodes.Clear();
            this.LoadTreeOrganize();

            // 更新控件，屏幕一次性刷新，提高效率。
            this.tvOrganize.EndUpdate();
        }

        #endregion private void LoadTree() 加载部门树的主键

        private void LoadTreeOrganize()
        {
            TreeNode treeNode = new TreeNode();
            this.LoadTreeOrganize(treeNode);
        }

        #region private void LoadTreeOrganize(TreeNode treeNode) 加载组织机构树的主键

        /// <summary>
        /// 加载组织机构树的主键
        /// </summary>
        /// <param name="TreeNode">当前节点</param>
        private void LoadTreeOrganize(TreeNode treeNode)
        {
            if ((BaseSystemInfo.UsePermissionScope) && !UserInfo.IsAdministrator)
            {
                BaseInterfaceLogic.CheckTreeParentId(this.DTOrganize, BaseOrganizeTable.FieldId, BaseOrganizeTable.FieldParentId);
            }
            BaseInterfaceLogic.LoadTreeNodes(this.DTOrganize, BaseOrganizeTable.FieldId, BaseOrganizeTable.FieldParentId, BaseOrganizeTable.FieldFullName, this.tvOrganize, treeNode, !BaseSystemInfo.OrganizeDynamicLoading);
        }

        #endregion private void LoadTreeOrganize(TreeNode treeNode) 加载组织机构树的主键

        #region private void DataTableAddColumn() 往DataSet里面添加一列

        /// <summary>
        /// 往DataSet里面添加一列
        /// </summary>
        private void DataTableAddColumn()
        {
            BaseInterfaceLogic.DataTableAddColumn(this.DTOrganizeList, BaseBusinessLogic.SelectedColumn);
            BaseInterfaceLogic.DataTableAddColumn(this.DTOrganize, BaseBusinessLogic.SelectedColumn);
       
            
        }

        #endregion private void DataTableAddColumn() 往DataSet里面添加一列

        #region private void SetSearch() 设置查询条件

        /// <summary>
        /// 设置查询条件
        /// </summary>
        private void SetSearch()
        {
            string search = this.txtSearch.Text;
            if (String.IsNullOrEmpty(search))
            {
                this.DTOrganizeList.DefaultView.RowFilter = string.Empty;
            }
            else
            {
                search = BaseBusinessLogic.GetSearchString(search);
                this.DTOrganize.DefaultView.RowFilter = BaseOrganizeTable.FieldCode + " LIKE '" + search + "'"
                    + " OR " + BaseOrganizeTable.FieldFullName + " LIKE '" + search + "'"
                    + " OR " + BaseOrganizeTable.FieldDescription + " LIKE '" + search + "'";
                this.grdOrganize.DataSource = this.DTOrganize.DefaultView;
            }

            // 设置按钮状态
            this.SetControlState();
        }

        #endregion private void SetSearch() 设置查询条件

        private void txtSearch_TextChanged(object sender, EventArgs e)
        {
            this.SetSearch();
        }

        private void btnSearch_Click(object sender, EventArgs e)
        {
            this.txtSearch.Text = this.txtSearch.Text.TrimEnd();
            if (this.txtSearch.Text.Trim().Length == 0)
            {
                DevExpress.XtraEditors.XtraMessageBox.Show(AppMessage.Format(AppMessage.MSG0007, AppMessage.MSG0212), AppMessage.MSG0000, MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.txtSearch.Focus();
                return;
            }

            // 设置鼠标繁忙状态
            this.Cursor = Cursors.WaitCursor;
            this.FormLoaded = false;

            // 点击了F5按钮
            ClientCache.Instance.DTOrganize = null;
            this.FormOnLoad();

            // 设置查询条件
            this.SetSearch();
            this.FormLoaded = true;

            // 设置鼠标默认状态
            this.Cursor = Cursors.Default;
        }

        private void chkInnerOrganize_CheckedChanged(object sender, EventArgs e)
        {
            this.OnLoad(e);
        }

        private void chkRefresh_CheckedChanged(object sender, EventArgs e)
        {
            if (this.chkRefresh.Checked)
            {
                ClientCache.Instance.DTOrganize = null;
                this.FormOnLoad();
            }
        }

        private void tvOrganize_AfterSelect(object sender, TreeViewEventArgs e)
        {
            if (this.FormLoaded)
            {
                if (this.ActiveControl == this.tvOrganize)
                {
                    if (this.tvOrganize.SelectedNode != null)
                    {
                        this.GetOrganizeList();
                    }
                }
            }
        }

        private void tvOrganize_Click(object sender, EventArgs e)
        {
            this.LastControl = this.tvOrganize;
            if (this.tvOrganize.SelectedNode == null)
            {
                this.tvOrganize.ContextMenuStrip = null;
            }
            else
            {
                this.tvOrganize.ContextMenuStrip = this.cMnuOrganize;
            }
            if (this.tvOrganize.SelectedNode != null)
            {
                this.GetOrganizeList();
            }
        }

        private void tvOrganize_DragEnter(object sender, DragEventArgs e)
        {
            // 拖动效果设成移动
            e.Effect = DragDropEffects.Move;
        }

        private void tvOrganize_ItemDrag(object sender, ItemDragEventArgs e)
        {
            if (this.permissionEdit)
            {
                // 开始进行拖放操作，并将拖放的效果设置成移动。
                this.DoDragDrop(e.Item, DragDropEffects.Move);
            }
        }

        private void tvOrganize_DragDrop(object sender, DragEventArgs e)
        {
            // 定义一个中间变量
            TreeNode treeNode;

            //判断拖动的是否为TreeNode类型，不是的话不予处理
            if (e.Data.GetDataPresent("System.Windows.Forms.TreeNode", false))
            {
                // 拖放的目标节点
                TreeNode targetTreeNode;

                // 获取当前光标所处的坐标
                // 定义一个位置点的变量，保存当前光标所处的坐标点
                Point point = ((TreeView)sender).PointToClient(new Point(e.X, e.Y));

                // 根据坐标点取得处于坐标点位置的节点
                targetTreeNode = ((TreeView)sender).GetNodeAt(point);

                // 获取被拖动的节点
                treeNode = (TreeNode)e.Data.GetData("System.Windows.Forms.TreeNode");

                // 判断拖动的节点与目标节点是否是同一个,同一个不予处理
                if (BaseInterfaceLogic.TreeNodeCanMoveTo(treeNode, targetTreeNode))
                {
                    if (BaseSystemInfo.ShowInformation)
                    {
                        // 是否移动部门
                        if (DevExpress.XtraEditors.XtraMessageBox.Show(AppMessage.Format(AppMessage.MSG0038, treeNode.Text, targetTreeNode.Text), AppMessage.MSG0000, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
                        {
                            return;
                        }
                    }
                    ServiceManager.Instance.OrganizeService.MoveTo(UserInfo, treeNode.Tag.ToString(), targetTreeNode.Tag.ToString());

                    // 往目标节点中加入被拖动节点的一份克隆
                    targetTreeNode.Nodes.Add((TreeNode)treeNode.Clone());

                    // 将被拖动的节点移除
                    treeNode.Remove();
                }
            }
        }

        private void mItmAdd_Click(object sender, EventArgs e)
        {
            this.btnAdd.PerformClick();
        }

        private void EditTree()
        {
            if (this.tvOrganize.SelectedNode == null)
            {
                return;
            }
            FrmOrganizeEdit frmOrganizeEdit = new FrmOrganizeEdit(this.tvOrganize.SelectedNode.Tag.ToString());
            if (frmOrganizeEdit.ShowDialog(this) == DialogResult.OK)
            {
                this.FormLoaded = false;
                if ((BaseSystemInfo.ClientCache) && (this.chkRefresh.Checked))
                {
                    ClientCache.Instance.DTOrganize = null;
                }
                if ((BaseSystemInfo.ClientCache) && (this.chkRefresh.Checked))
                {
                    ClientCache.Instance.DTOrganize = null;
                }

                // 绑定屏幕数据
                this.BindData(true);
                this.FormLoaded = true;
            }
        }

        private void mItmEdit_Click(object sender, EventArgs e)
        {
            this.EditTree();
        }

        private void mItmMove_Click(object sender, EventArgs e)
        {
            this.btnMove.PerformClick();
        }

        private void mItmDelete_Click(object sender, EventArgs e)
        {
            this.LastControl = this.tvOrganize;
            this.btnBatchDelete.PerformClick();
        }

        private void mItmAddRoot_Click(object sender, EventArgs e)
        {
            this.Add(true);
        }

        private void mItmAddStaff_Click(object sender, EventArgs e)
        {
            // 用反射获得窗体
            string assemblyName = "DotNet.WinForm.Staff";
            string formName = "FrmStaffAdd";
            Form frmStaffAdd = CacheManager.Instance.GetForm(assemblyName, formName);
            if (this.tvOrganize.SelectedNode != null)
            {
                string DepartmentId = string.Empty;
                string departmentFullName = string.Empty;
                string CompanyId = string.Empty;
                string companyFullName = string.Empty;
                TreeNode treeNode = this.tvOrganize.SelectedNode;
                if (BaseBusinessLogic.GetProperty(ClientCache.Instance.DTOrganize, treeNode.Tag.ToString(), BaseOrganizeTable.FieldCategory) != OrganizeCategory.Company.ToString())
                {
                    DepartmentId = treeNode.Tag.ToString();
                    departmentFullName = treeNode.Text;
                }
                while (treeNode.Parent != null)
                {
                    if (BaseBusinessLogic.GetProperty(ClientCache.Instance.DTOrganize, treeNode.Tag.ToString(), BaseOrganizeTable.FieldCategory) == OrganizeCategory.Company.ToString())
                    {
                        CompanyId = treeNode.Tag.ToString();
                        companyFullName = treeNode.Text;
                        break;
                    }
                    treeNode = treeNode.Parent;
                }
                ((IBaseStaffAddForm)frmStaffAdd).CompanyId = CompanyId;
                ((IBaseStaffAddForm)frmStaffAdd).CompanyFullName = companyFullName;
                ((IBaseStaffAddForm)frmStaffAdd).DepartmentId = DepartmentId;
                ((IBaseStaffAddForm)frmStaffAdd).DepartmentFullName = departmentFullName;
            }
            frmStaffAdd.ShowDialog(this);
        }

        private void mItmAddRole_Click(object sender, EventArgs e)
        {
            // 用反射获得窗体
            string assemblyName = "DotNet.WinForm.Role";
            string formName = "FrmOrganizeRoleAdd";
            Form frmOrganizeRoleAdd = CacheManager.Instance.GetForm(assemblyName, formName);
            if (this.tvOrganize.SelectedNode != null)
            {
                ((IBaseOrganizeRoleAddForm)frmOrganizeRoleAdd).OrganizeId = this.tvOrganize.SelectedNode.Tag.ToString();
                ((IBaseOrganizeRoleAddForm)frmOrganizeRoleAdd).OrganizeFullName = this.tvOrganize.SelectedNode.Text;
            }
            frmOrganizeRoleAdd.ShowDialog(this);
        }

        private void mItmOrganizeCategory_Click(object sender, EventArgs e)
        {
            // 用反射获得窗体
            string assemblyName = "DotNet.WinForm.Items";
            string formName = "FrmItemDetailsAdmin";
            Form frmItemDetailsAdmin = CacheManager.Instance.GetForm(assemblyName, formName);
            ((IBaseItemDetailsAdminForm)frmItemDetailsAdmin).TargetTable = "Items_OrganizeCategory";
            var dlg = frmItemDetailsAdmin.ShowDialog(this);
            if (dlg == DialogResult.OK)
            {
                this.FormLoaded = false;

                // 绑定屏幕数据
                this.BindData(true);
                this.FormLoaded = true;
            }
        }

        private void mItmFrmUserModuleOperationReport_Click(object sender, EventArgs e)
        {
            if (this.tvOrganize.SelectedNode != null)
            {
                //FrmUserModuleOperationReport FrmUserModuleOperationReport = new FrmUserModuleOperationReport(this.tvOrganize.SelectedNode.Tag.ToString(), this.tvOrganize.SelectedNode.Text);
                //FrmUserModuleOperationReport.ShowDialog(this);
                //if (frmItemDetailsAdmin.ShowDialog(this) == DialogResult.OK)
                //{
                //    this.FormLoaded = false;

                //    // 绑定屏幕数据
                //    this.BindData(true);
                //    this.FormLoaded = true;
                //}
            }
        }

        private string organizeList = string.Empty;

        private void GetTreeSort(TreeNode treeNode)
        {
            organizeList += treeNode.Tag.ToString() + ",";
            for (int i = 0; i < treeNode.Nodes.Count; i++)
            {
                this.GetTreeSort(treeNode.Nodes[i]);
            }
        }

        #region private string[] GetTreeSort() 获得树型机构的排序顺序

        /// <summary>
        /// 获得树型机构的排序顺序
        /// </summary>
        /// <returns>主键数组</returns>
        private string[] GetTreeSort()
        {
            string[] ids = new string[0];
            if (UserInfo.IsAdministrator)
            {
                this.organizeList = string.Empty;
                for (int i = 0; i < this.tvOrganize.Nodes.Count; i++)
                {
                    this.GetTreeSort(this.tvOrganize.Nodes[i]);
                }
                if (this.organizeList.Length > 0)
                {
                    this.organizeList = this.organizeList.Substring(0, this.organizeList.Length - 1);
                    ids = this.organizeList.Split(',');
                }
            }
            return ids;
        }

        #endregion private string[] GetTreeSort() 获得树型机构的排序顺序

        private void mItmSetSortCode_Click(object sender, EventArgs e)
        {
            // 设置鼠标繁忙状态
            this.Cursor = Cursors.WaitCursor;
            if (this.permissionEdit)
            {
                ServiceManager.Instance.OrganizeService.BatchSetSortCode(UserInfo, this.GetTreeSort());
            }

            // 设置鼠标默认状态
            this.Cursor = Cursors.Default;
        }

        private void mItmFrmOrganizeCodeBuilder_Click(object sender, EventArgs e)
        {
            FrmOrganizeCodeBuilder FrmOrganizeCodeBuilder = new FrmOrganizeCodeBuilder(this.tvOrganize);
            if (FrmOrganizeCodeBuilder.ShowDialog(this) == DialogResult.OK)
            {
                this.GetOrganizeList();
            }
        }

        private void grdOrganize_Click(object sender, EventArgs e)
        {
            this.LastControl = this.grdOrganize;
        }

        private void grdOrganize_CellDoubleClick(object sender, EventArgs e)
        {
            this.btnEdit.PerformClick();
        }

        /// <summary>
        /// 置顶
        /// </summary>
        public int SetTop()
        {
            return this.ucTableSort.SetTop();
        }

        /// <summary>
        /// 上移
        /// </summary>
        public int SetUp()
        {
            return this.ucTableSort.SetUp();
        }

        /// <summary>
        /// 下移
        /// </summary>
        public int SetDown()
        {
            return this.ucTableSort.SetDown();
        }

        /// <summary>
        /// 置底
        /// </summary>
        public int SetBottom()
        {
            return this.ucTableSort.SetBottom();
        }

        public void SetSortButton(bool enabled)
        {
            this.ucTableSort.SetSortButton(enabled);
        }

        #region private string[] GetSelecteIds() 获得已被选择的部门主键数组

        /// <summary>
        /// 获得已被选择的部门主键数组
        /// </summary>
        /// <returns>主键数组</returns>
        private string[] GetSelecteIds()
        {
            return BaseInterfaceLogic.GetSelecteIds(this.DTOrganizeList, BaseOrganizeTable.FieldId, BaseBusinessLogic.SelectedColumn);
        }

        #endregion private string[] GetSelecteIds() 获得已被选择的部门主键数组

        private void grdOrganize_Sorted(object sender, EventArgs e)
        {
            // 设置鼠标繁忙状态
            this.Cursor = Cursors.WaitCursor;
            if (this.permissionEdit)
            {
                string[] sequence = ServiceManager.Instance.SequenceService.GetBatchSequence(UserInfo, BaseOrganizeTable.TableName, this.DTOrganizeList.DefaultView.Count);
                int i = 0;
                foreach (DataRowView dataRowView in this.DTOrganizeList.DefaultView)
                {
                    dataRowView.Row[BaseOrganizeTable.FieldSortCode] = sequence[i];
                    i++;
                }

                // 控制导航按钮
                this.SetSortButton(false);
            }

            // 设置鼠标默认状态
            this.Cursor = Cursors.Default;
        }

        public string Add()
        {
            return this.Add(false);
        }

        #region private void Add(bool root) 添加组织机构

        /// <summary>
        /// 添加组织机构
        /// </summary>
        /// <returns>主键</returns>
        public string Add(bool root)
        {
            string returnValue = string.Empty;
            FrmOrganizeAdd frmOrganizeAdd;
            if (this.LastControl == this.tvOrganize)
            {
                if ((root) || (this.ParentEntityId.Length == 0) || (this.tvOrganize.SelectedNode == null))
                {
                    frmOrganizeAdd = new FrmOrganizeAdd();
                }
                else
                {
                    frmOrganizeAdd = new FrmOrganizeAdd(this.ParentEntityId, this.tvOrganize.SelectedNode.Text);
                }
            }
            else
            {
                DataRow dataRow = BaseInterfaceLogic.GetDataGridViewEntity(this.grdOrganize);
                if ((root) || dataRow == null)
                {
                    frmOrganizeAdd = new FrmOrganizeAdd();
                }
                else
                {
                    frmOrganizeAdd = new FrmOrganizeAdd(dataRow[BaseOrganizeTable.FieldId].ToString(), dataRow[BaseOrganizeTable.FieldFullName].ToString());
                }
            }
            if (frmOrganizeAdd.ShowDialog(this) == DialogResult.OK)
            {
                returnValue = frmOrganizeAdd.EntityId;
                this.FormLoaded = false;
                if ((BaseSystemInfo.ClientCache) && (this.chkRefresh.Checked))
                {
                    ClientCache.Instance.DTOrganize = null;
                }

                // 绑定屏幕数据
                this.BindData(true);
                this.FormLoaded = true;
            }
            return returnValue;
        }

        #endregion private void Add(bool root) 添加组织机构

        private void btnAdd_Click(object sender, EventArgs e)
        {
            // 添加组织机构
            this.Add(false);
        }

        #region private void EditGrid() 编辑组织机构

        /// <summary>
        /// 编辑组织机构
        /// </summary>
        private void EditGrid()
        {
            FrmOrganizeEdit frmOrganizeEdit = new FrmOrganizeEdit(this.EntityId);
            if (frmOrganizeEdit.ShowDialog(this) == DialogResult.OK)
            {
                this.FormLoaded = false;
                if ((BaseSystemInfo.ClientCache) && (this.chkRefresh.Checked))
                {
                    ClientCache.Instance.DTOrganize = null;
                }

                // 绑定屏幕数据
                this.BindData(true);
                this.FormLoaded = true;
            }
        }

        #endregion private void EditGrid() 编辑组织机构

        /// <summary>
        /// 编辑
        /// </summary>
        public void Edit()
        {
            // 编辑组织机构
            if (this.LastControl == this.grdOrganize)
            {
                this.EditGrid();
            }
            if (this.LastControl == this.tvOrganize)
            {
                this.EditTree();
            }
        }

        private void btnEdit_Click(object sender, EventArgs e)
        {
            this.Edit();
        }

        #region private bool CheckInputMove(string selectedId) 检查能否移动

        /// <summary>
        /// 检查能否移动
        /// </summary>
        /// <returns>能否移动到目标位置</returns>
        private bool CheckInputMove(string selectedId)
        {
            bool returnValue = true;

            // 单个移动检查
            if (this.LastControl == this.tvOrganize)
            {
                BaseInterfaceLogic.FindTreeNode(this.tvOrganize, this.parentEntityId);
                TreeNode treeNode = BaseInterfaceLogic.TargetNode;
                BaseInterfaceLogic.FindTreeNode(this.tvOrganize, selectedId);
                TreeNode targetTreeNode = BaseInterfaceLogic.TargetNode;
                if (treeNode != null)
                {
                    if (!BaseInterfaceLogic.TreeNodeCanMoveTo(treeNode, targetTreeNode))
                    {
                        DevExpress.XtraEditors.XtraMessageBox.Show(AppMessage.Format(AppMessage.MSG0036, treeNode.Text, targetTreeNode.Text), AppMessage.MSG0000, MessageBoxButtons.OK, MessageBoxIcon.Information);
                        returnValue = false;
                    }
                }
            }

            // 进行批量检查
            if (this.LastControl == this.grdOrganize)
            {
                BaseInterfaceLogic.FindTreeNode(this.tvOrganize, selectedId);
                TreeNode targetTreeNode = BaseInterfaceLogic.TargetNode;
                string[] SelecteIds = this.GetSelecteIds();
                for (int i = 0; i < SelecteIds.Length; i++)
                {
                    BaseInterfaceLogic.FindTreeNode(this.tvOrganize, SelecteIds[i]);
                    TreeNode treeNode = BaseInterfaceLogic.TargetNode;
                    if (!BaseInterfaceLogic.TreeNodeCanMoveTo(treeNode, targetTreeNode))
                    {
                        DevExpress.XtraEditors.XtraMessageBox.Show(AppMessage.Format(AppMessage.MSG0036, treeNode.Text, targetTreeNode.Text), AppMessage.MSG0000, MessageBoxButtons.OK, MessageBoxIcon.Information);
                        returnValue = false;
                        break;
                    }
                }
            }
            return returnValue;
        }

        #endregion private bool CheckInputMove(string selectedId) 检查能否移动

        #region private void BatchMove() 批量移动

        /// <summary>
        /// 批量移动
        /// </summary>
        private void BatchMove()
        {
            if (BaseInterfaceLogic.CheckInputSelectAnyOne(this.DTOrganizeList, BaseBusinessLogic.SelectedColumn))
            {
                FrmOrganizeSelect FrmOrganizeSelect = new FrmOrganizeSelect(this.parentEntityId, this.chkInnerOrganize.Checked);
                if (UserInfo.IsAdministrator)
                {
                    FrmOrganizeSelect.AllowNull = true;
                }
                else
                {
                    FrmOrganizeSelect.AllowNull = false;
                    FrmOrganizeSelect.ByPermission = this.ByPermission;
                }
                FrmOrganizeSelect.OnButtonConfirmClick += new BaseBusinessLogic.CheckMoveEventHandler(CheckInputMove);
                if (FrmOrganizeSelect.ShowDialog() == DialogResult.OK)
                {
                    // 设置鼠标繁忙状态
                    this.Cursor = Cursors.WaitCursor;
                    this.FormLoaded = false;
                    ServiceManager.Instance.OrganizeService.BatchMoveTo(UserInfo, this.GetSelecteIds(), FrmOrganizeSelect.SelectedId);
                    if ((BaseSystemInfo.ClientCache) && (this.chkRefresh.Checked))
                    {
                        ClientCache.Instance.DTOrganize = null;
                    }

                    // 绑定屏幕数据
                    this.BindData(true);
                    this.FormLoaded = true;

                    // 设置鼠标默认状态
                    this.Cursor = Cursors.Default;
                }
            }
        }

        #endregion private void BatchMove() 批量移动

        #region private void SingleMove() 单个记录移动

        /// <summary>
        /// 单个记录移动
        /// </summary>
        public void SingleMove(string currentEntityId)
        {
            FrmOrganizeSelect frmOrganizeSelect = new FrmOrganizeSelect(this.parentEntityId, this.chkInnerOrganize.Checked);
            if (UserInfo.IsAdministrator)
            {
                frmOrganizeSelect.AllowNull = true;
            }
            else
            {
                frmOrganizeSelect.AllowNull = false;
                frmOrganizeSelect.ByPermission = this.ByPermission;
            }
            frmOrganizeSelect.OnButtonConfirmClick += new BaseBusinessLogic.CheckMoveEventHandler(CheckInputMove);
            if (frmOrganizeSelect.ShowDialog() == DialogResult.OK)
            {
                // 设置鼠标繁忙状态
                this.Cursor = Cursors.WaitCursor;
                this.FormLoaded = false;
                ServiceManager.Instance.OrganizeService.MoveTo(UserInfo, currentEntityId, frmOrganizeSelect.SelectedId);
                if (!BaseSystemInfo.ClientCache)
                {
                    ClientCache.Instance.DTOrganize = null;
                }
                this.FormLoaded = false;
                if ((BaseSystemInfo.ClientCache) && (this.chkRefresh.Checked))
                {
                    ClientCache.Instance.DTOrganize = null;
                }

                // 绑定屏幕数据
                this.BindData(true);
                this.FormLoaded = true;

                // 设置鼠标默认状态
                this.Cursor = Cursors.Default;
            }
        }

        #endregion private void SingleMove() 单个记录移动

        #region private void MoveObject() 移动数据

        /// <summary>
        /// 移动数据
        /// </summary>
        private void MoveObject()
        {
            if (this.LastControl == this.grdOrganize)
            {
                this.BatchMove();
                this.FormOnLoad();
            }
            if (this.LastControl == this.tvOrganize)
            {
                if (this.parentEntityId.Length > 0)
                {
                    this.SingleMove(this.CurrentEntityId);
                    this.FormOnLoad();
                }
            }
        }

        #endregion private void MoveObject() 移动数据

        private void btnMove_Click(object sender, EventArgs e)
        {
            // 移动数据
            this.MoveObject();
        }

        private void btnExport_Click(object sender, EventArgs e)
        {
            // 导出Excel
            this.ExportExcel(this.frmdefaultGridView, @"\Modules\Export\", "组织机构.csv");
        }

        #region private bool CheckInputBatchDelete() 检查输入的有效性

        /// <summary>
        /// 检查删除选择项的有效性
        /// </summary>
        /// <returns>有效</returns>
        private bool CheckInputBatchDelete()
        {
            bool returnValue = false;
            foreach (DataRow dataRow in this.DTOrganizeList.Rows)
            {
                if (dataRow[BaseBusinessLogic.SelectedColumn].ToString() == true.ToString())
                {
                    // 有记录被选中了
                    returnValue = true;
                    // break;
                    // 是否有子节点
                    string id = dataRow[BaseOrganizeTable.FieldId].ToString();
                    BaseInterfaceLogic.FindTreeNode(this.tvOrganize, id);
                    if (BaseInterfaceLogic.TargetNode != null)
                    {
                        if (!BaseInterfaceLogic.NodeAllowDelete(BaseInterfaceLogic.TargetNode))
                        {
                            DevExpress.XtraEditors.XtraMessageBox.Show(AppMessage.Format(AppMessage.MSG0035, BaseInterfaceLogic.TargetNode.Text), AppMessage.MSG0000, MessageBoxButtons.OK, MessageBoxIcon.Information);
                            returnValue = false;
                            return returnValue;
                        }
                    }
                }
            }
            if (!returnValue)
            {
                DevExpress.XtraEditors.XtraMessageBox.Show(AppMessage.MSG0023, AppMessage.MSG0000, MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            return returnValue;
        }

        #endregion private bool CheckInputBatchDelete() 检查输入的有效性

        #region public override int BatchDelete() 批量删除

        /// <summary>
        /// 批量删除
        /// </summary>
        /// <returns>影响行数</returns>
        public override int BatchDelete()
        {
            int returnValue = 0;
            if (!BaseSystemInfo.ClientCache)
            {
                ClientCache.Instance.DTOrganize = null;
            }
            this.FormLoaded = false;

            // returnValue = ServiceManager.Instance.OrganizeService.BatchDelete(UserInfo, this.GetSelecteIds());
            returnValue = ServiceManager.Instance.OrganizeService.SetDeleted(UserInfo, this.GetSelecteIds());
            if ((BaseSystemInfo.ClientCache) && (this.chkRefresh.Checked))
            {
                ClientCache.Instance.DTOrganize = null;
            }

            // 绑定数据
            this.BindData(true);
            this.FormLoaded = true;
            return returnValue;
        }

        #endregion public override int BatchDelete() 批量删除

        #region private int SingleDelete() 单个记录删除

        /// <summary>
        /// 单个记录删除
        /// </summary>
        /// <returns>影响行数</returns>
        public int SingleDelete()
        {
            int returnValue = 0;

            // 设置鼠标繁忙状态
            this.Cursor = Cursors.WaitCursor;
            this.FormLoaded = false;

            // returnValue = ServiceManager.Instance.OrganizeService.Delete(UserInfo, this.ParentEntityId);
            returnValue = ServiceManager.Instance.OrganizeService.SetDeleted(UserInfo, new String[] { this.ParentEntityId });
            this.FormLoaded = false;
            if ((BaseSystemInfo.ClientCache) && (this.chkRefresh.Checked))
            {
                ClientCache.Instance.DTOrganize = null;

                // 绑定屏幕数据
                this.BindData(true);
            }
            else
            {
                if (this.tvOrganize.SelectedNode != null)
                {
                    this.tvOrganize.SelectedNode.Remove();
                }
            }
            this.FormLoaded = true;

            // 设置鼠标默认状态
            this.Cursor = Cursors.Default;
            return returnValue;
        }

        #endregion private int SingleDelete() 单个记录删除

        #region public int Delete() 删除数据

        /// <summary>
        /// 删除数据
        /// </summary>
        ///
        public int Delete()
        {
            int returnValue = 0;
            if (this.LastControl == this.grdOrganize)
            {
                if (this.CheckInputBatchDelete())
                {
                    if (DevExpress.XtraEditors.XtraMessageBox.Show(AppMessage.MSG0015, AppMessage.MSG0000, MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.OK)
                    {
                        // 设置鼠标繁忙状态
                        this.Cursor = Cursors.WaitCursor;
                        try
                        {
                            returnValue = this.BatchDelete();
                        }
                        catch (Exception ex)
                        {
                            this.ProcessException(ex);
                        }
                        finally
                        {
                            // 设置鼠标默认状态
                            this.Cursor = Cursors.Default;
                        }
                    }
                }
            }
            if (this.LastControl == this.tvOrganize)
            {
                if (!BaseInterfaceLogic.NodeAllowDelete(this.tvOrganize.SelectedNode))
                {
                    DevExpress.XtraEditors.XtraMessageBox.Show(AppMessage.Format(AppMessage.MSG0035, this.tvOrganize.SelectedNode.Text), AppMessage.MSG0000, MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    if (DevExpress.XtraEditors.XtraMessageBox.Show(AppMessage.MSG0015, AppMessage.MSG0000, MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.OK)
                    {
                        // 设置鼠标繁忙状态
                        this.Cursor = Cursors.WaitCursor;
                        try
                        {
                            returnValue = this.SingleDelete();
                        }
                        catch (Exception ex)
                        {
                            this.ProcessException(ex);
                        }
                        finally
                        {
                            // 设置鼠标默认状态
                            this.Cursor = Cursors.Default;
                        }
                    }
                }
            }
            return returnValue;
        }

        #endregion public int Delete() 删除数据

        private void btnBatchDelete_Click(object sender, EventArgs e)
        {
            // 删除数据
            this.Delete();
        }

        #region private void BatchSave() 批量保存

        /// <summary>
        /// 批量保存
        /// </summary>
        private void BatchSave()
        {
            this.FormLoaded = false;
            ServiceManager.Instance.OrganizeService.BatchSave(UserInfo, this.DTOrganizeList);
            if (!BaseSystemInfo.ClientCache)
            {
                ClientCache.Instance.DTOrganize = null;
            }

            // 绑定数据
            this.BindData(true);
            this.FormLoaded = true;
            if (BaseSystemInfo.ShowInformation)
            {
                // 批量保存，进行提示
                DevExpress.XtraEditors.XtraMessageBox.Show(AppMessage.MSG0011, AppMessage.MSG0000, MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }

        #endregion private void BatchSave() 批量保存

        /// <summary>
        /// 保存
        /// </summary>
        public void Save()
        {
            // 检查批量输入的有效性
            if (BaseInterfaceLogic.CheckInputModifyAnyOne(this.DTOrganizeList))
            {
                // 设置鼠标繁忙状态
                this.Cursor = Cursors.WaitCursor;
                try
                {
                    // 批量保存
                    this.BatchSave();
                }
                catch (Exception ex)
                {
                    this.ProcessException(ex);
                }
                finally
                {
                    // 设置鼠标默认状态
                    this.Cursor = Cursors.Default;
                }
            }
        }

        private void btnBatchSave_Click(object sender, EventArgs e)
        {
            this.Save();
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void FrmOrganizeAdmin_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (BaseInterfaceLogic.IsModfiedAnyOne(this.DTOrganizeList))
            {
                // 数据有变动是否保存的提示
                DialogResult dialogResult = DevExpress.XtraEditors.XtraMessageBox.Show(AppMessage.MSG0045, AppMessage.MSG0000, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button3);
                if (dialogResult == DialogResult.Cancel)
                {
                    e.Cancel = true;
                }
                else if (dialogResult == DialogResult.Yes)
                {
                    // 保存数据
                    this.BatchSave();
                }
            }
        }

        /// <summary>
        /// 添加用户
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void mItmUserAdd_Click(object sender, EventArgs e)
        {
            // 用反射获得窗体
            string assemblyName = "DotNet.WinForm.User";
            string formName = "FrmUserAdd";
            Form frmUserAdd = CacheManager.Instance.GetForm(assemblyName, formName);
            if (this.tvOrganize.SelectedNode != null)
            {
                string DepartmentId = string.Empty;
                string departmentFullName = string.Empty;
                string CompanyId = string.Empty;
                string companyFullName = string.Empty;
                TreeNode treeNode = this.tvOrganize.SelectedNode;
                if (BaseBusinessLogic.GetProperty(ClientCache.Instance.DTOrganize, treeNode.Tag.ToString(), BaseOrganizeTable.FieldCategory) != OrganizeCategory.Company.ToString())
                {
                    DepartmentId = treeNode.Tag.ToString();
                    departmentFullName = treeNode.Text;
                }
                while (treeNode.Parent != null)
                {
                    if (BaseBusinessLogic.GetProperty(ClientCache.Instance.DTOrganize, treeNode.Tag.ToString(), BaseOrganizeTable.FieldCategory) == OrganizeCategory.Company.ToString())
                    {
                        CompanyId = treeNode.Tag.ToString();
                        companyFullName = treeNode.Text;
                        break;
                    }
                    treeNode = treeNode.Parent;
                }
            }
            frmUserAdd.ShowDialog(this);
            if (frmUserAdd.ShowDialog(this) == DialogResult.OK)
            {
                this.FormLoaded = false;

                // 绑定屏幕数据
                this.BindData(true);
                this.FormLoaded = true;
            }
        }

        private void tvOrganize_MouseDown(object sender, MouseEventArgs e)
        {
            if (tvOrganize.GetNodeAt(e.X, e.Y) != null)
            {
                tvOrganize.SelectedNode = tvOrganize.GetNodeAt(e.X, e.Y);
            }
        }
    }
}